import 'package:flutter/material.dart';
import 'package:cook_dinner/config/include.dart';

class AppBarCustom extends StatelessWidget implements PreferredSizeWidget {
  AppBarCustom(this.title,
      {Key? key,
      this.actions,
      this.back = true,
      this.bottom,
      this.height,
      this.color,
      this.bgColor,
      this.size})
      : mypreferredSize =
            Size.fromHeight(height ?? 30.rpx + HYSizeFit.statusHeight),
        super(key: key);

  final String title;
  final double? height;
  final Size mypreferredSize; // 明确声明preferredSize
  final List<Widget>? actions;
  final PreferredSizeWidget? bottom;
  final bool back;
  final Color? color;
  final Color? bgColor;
  final double? size;

  @override
  Widget build(BuildContext context) {
    return PreferredSize(
      preferredSize: mypreferredSize,
      child: AppBar(
        toolbarHeight: height ?? 30.rpx + HYSizeFit.statusHeight,
        elevation: 0,
        backgroundColor: bgColor ?? Colors.white,
        centerTitle: true,
        title: Text(
          title,
          style: TextStyle(
            fontSize: size ?? 20.rpx,
            color: color ?? const Color(0xff000000),
            fontWeight: FontWeight.w400,
          ),
        ),
        leading: back
            ? InkWell(
                onTap: () => Navigator.pop(context),
                child: Image.asset(
                  'assets/images/back_left.png',
                  width: 12.rpx,
                  height: 24.rpx,
                ),
              )
            : const SizedBox(),
        actions: actions ?? [],
        bottom: bottom,
      ),
    );
  }

  @override
  Size get preferredSize => mypreferredSize; // 实现PreferredSizeWidget接口
}
